use crate::shadow;
use clap::crate_authors;
use clap::ColorChoice;
use clap::{Parser, Subcommand};
use rust_i18n::t;

pub const USE_VERSION_DEFAULT: &str = "0";

#[derive(Parser, Debug)]
#[command(
    author=crate_authors!(),
    version=shadow::PKG_VERSION,
    long_version=shadow::CLAP_LONG_VERSION,
    color = ColorChoice::Auto,
    about=t!("app_about").to_string(),
    arg_required_else_help=true,
    long_about=t!("app_long_about").to_string(),
    before_help =format!("👏vch version:{}",shadow::PKG_VERSION),
    after_help = format!("📄document:https://vch.vsoc.top\n📧author:{}",crate_authors!()),
)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Subcommand, Debug)]
pub enum Commands {
    /// Configuration Manager
    #[clap(alias = "c", about = t!("cli_config_help").to_string())]
    Config(ConfigCliArgs),
    /// SDK and Version Manager
    #[clap(alias = "v", about = t!("cli_version_help").to_string())]
    Version(VersionCliArgs),
    /// Change Source
    #[clap(alias = "s", about = t!("cli_source_help").to_string())]
    Source(SourceCliArgs),

    #[clap(alias = "u", about = t!("cli_upgrade_help").to_string())]
    Upgrade {
        #[arg(skip,help = t!("cli_upgrade_help").to_string())]
        upgrade: bool,
    },
    #[cfg(feature = "test")]
    #[clap(alias = "t", about = "test")]
    Test,
}

#[derive(Parser, Debug)]
pub struct ConfigCliArgs {
    /// Configuration Key
    #[clap(help=t!("cli_config_key_help").to_string())]
    pub key: String,

    /// Configuration Value
    #[clap(help=t!("cli_config_value_help").to_string())]
    pub value: String,

    /// Configuration
    #[arg(short, long,help = t!("cli_config_list_help").to_string())]
    pub list: bool,

    /// Configuration
    #[arg(short, long, help = t!("cli_config_default_help").to_string())]
    pub default: bool,

    #[arg(short, long, help = t!("cli_config_remove_help").to_string(),num_args = ..)]
    pub remove: String,
}

#[derive(Parser, Debug)]
pub struct VersionCliArgs {
    /// show all sdk
    #[arg(short, long, help = t!("cli_version_list_help").to_string())]
    pub list: bool,

    /// show current sdk
    #[arg(short, long,help = t!("cli_version_current_help").to_string())]
    pub current: bool,

    // change sdk and version
    #[command(subcommand)]
    pub command: Option<VersionSubCommands>,
}

#[derive(Parser, Debug)]
pub struct SourceCliArgs {
    /// show all source
    #[arg(short, long,help = t!("cli_source_list_help").to_string(),num_args = 0..=1)]
    pub list: String,

    /// show support source
    #[arg(short, long,help = t!("cli_source_support_help").to_string())]
    pub support: bool,

    /// Source name
    #[clap(help=t!("cli_source_name_help").to_string())]
    pub name: String,

    /// Option
    #[arg(short, long,help = t!("cli_source_target_help").to_string(),num_args = 1..)]
    pub target: Option<String>,
}

#[derive(Parser, Debug)]
pub enum VersionSubCommands {
    #[clap(about=t!("cli_version_use_help").to_string())]
    Use {
        /// SDK Name and version
        #[clap(help=t!("cli_version_name_help").to_string())]
        name: String,

        #[clap(default_value = USE_VERSION_DEFAULT,help=t!("cli_version_version_help").to_string())]
        version: String,

        #[arg(short, long,help = t!("cli_version_use_global_help").to_string())]
        global: bool,

        #[arg(short, long,help = t!("cli_version_use_project_help").to_string())]
        project: bool,

        #[arg(short, long,help = t!("cli_version_use_session_help").to_string())]
        session: bool,
    },
    #[clap(about=t!("cli_version_remove_help").to_string())]
    Remove {
        #[clap(help=t!("cli_version_name_help").to_string())]
        name: String,
        #[clap(default_value = USE_VERSION_DEFAULT,help=t!("cli_version_version_help").to_string())]
        version: String,
    },
    #[clap(alias="a", about=t!("cli_version_add_help").to_string())]
    Add {
        #[clap(help=t!("cli_version_name_help").to_string())]
        name: String,

        #[clap(default_value = USE_VERSION_DEFAULT, help=t!("cli_version_version_help").to_string())]
        version: String,
    },
    #[clap(alias="s", about=t!("cli_version_search_help").to_string())]
    Search {
        #[clap(help=t!("cli_version_name_help").to_string())]
        name: String,
    },
    Plugin {
        #[arg(short, long, help = "inner name")]
        name: String,
    },
}
